package com.hanhai;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.MonthDay;

/**
 * @author weijingchen
 * @DateTime 2025-05-26
 */
public class LocalDateTest {
    public static void main(String[] args) {
        //1、获取当前时间
        LocalDate now = LocalDate.now();
        System.out.println("现在日期是："+now);
        //2、获取指定时间
        LocalDate ldDate = LocalDate.of(2025, 5, 26);
        System.out.println("获取指定时间是"+ldDate);
        //3、获取日历对象中的年月日
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        System.out.println("年："+year+"月："+month+"日："+day);

        Month month1 = now.getMonth();
        System.out.println("当前时间是"+month1+"(英文时间)");


        //3.1 获取当前时间是本月的第几天
        int dayOfMonth = now.getDayOfMonth();
        System.out.println("本月第"+dayOfMonth+"天");
        //3.2 获取当前时间是本周的第几天
        int dayOfWeek = now.getDayOfWeek().getValue();
        System.out.println("本周第"+dayOfWeek+"天");
        //3.3 获取当前时间是本年的第几天
        DayOfWeek dayOfWeek1 = now.getDayOfWeek();
        System.out.println("本年第"+dayOfWeek1+"天");
        //3.4 获取当前时间是本年的第几天
        int dayOfYear = now.getDayOfYear();
        System.out.println("本年第"+dayOfYear+"天");

        //4、判断时间对象是否相等
        LocalDate ldDate1 = LocalDate.of(2025, 5, 25);
        boolean equals = ldDate.equals(ldDate1);
        System.out.println("时间对象是否相等："+equals);

        //5、判断时间对象是否在时间对象之前或之后
        boolean before = ldDate.isBefore(ldDate1);
        System.out.println("ldDate是否在ldDate1之前："+before);
        boolean after = ldDate.isAfter(ldDate1);
        System.out.println("ldDate是否在ldDate1之后："+after);
        System.out.println("----------------------2025-05-26------------------------------------------");

        //6、withXxx 修改时间对象
        LocalDate ldDate2 = ldDate.withYear(2024);
        System.out.println("修改时间对象年的时间："+ldDate2);
        LocalDate ldDate3 = ldDate.withMonth(6);
        System.out.println("修改时间对象月的时间："+ldDate3);
        LocalDate ldDate4 = ldDate.withDayOfMonth(1);
        System.out.println("修改时间对象当月第1天："+ldDate4);
        LocalDate ldDate5 = ldDate.withDayOfYear(1);
        System.out.println("修改时间对象为当年的第1天，会自动转换月："+ldDate5);
        System.out.println("----------------------2025-05-26------------------------------------------");

        //7、plusXxx 添加时间
        LocalDate ldDate6 = ldDate.plusYears(1);
        System.out.println("添加1年："+ldDate6);
        LocalDate ldDate7 = ldDate.plusMonths(1);
        System.out.println("添加1个月："+ldDate7);
        LocalDate ldDate8 = ldDate.plusDays(1);
        System.out.println("添加1天："+ldDate8);

        System.out.println("----------------------2025-05-26------------------------------------------");
        //8、minusXxx 减少时间
        LocalDate ldDate9 = ldDate.minusYears(1);
        System.out.println("减少1年："+ldDate9);
        LocalDate ldDate10 = ldDate.minusMonths(1);
        System.out.println("减少1个月："+ldDate10);
        LocalDate ldDate11 = ldDate.minusDays(1);
        System.out.println("减少1天："+ldDate11);
        LocalDate ldDate12 = ldDate.minusWeeks(1);
        System.out.println("减少1周："+ldDate12);

        //9、判断今天是否是你的生日，将时间对象转换为MonthDay对象，再判断是否相等
        System.out.println("----------------------2025-05-26------------------------------------------");

        LocalDate ldDate13 = LocalDate.of(2025, 5, 26);
        MonthDay  monthDay = MonthDay.of(ldDate13.getMonth(), ldDate13.getDayOfMonth());
        MonthDay  monthDay1 = MonthDay.now();
        if (monthDay.equals(monthDay1)){
            System.out.println("今天是你的生日");
        }else {
            System.out.println("今天不是你的生日");
        }

    }
}
